package com.yanqu.road.server.cmd.activity.sonhai;

import com.yanqu.road.entity.activity.sonhai.param.SonHaiGetPlotDetailResp;
import com.yanqu.road.entity.activity.sonhai.param.SonHaiPatronsEgg;
import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SonHaiProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiActivity;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiActivityMgr;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiUser;
import com.yanqu.road.server.manager.activity.sonhai.pb.SonHaiActivityPb;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;
import java.util.Map;

@Cmd(code = Protocol.C2_SON_HAI_GET_IN_EGG_PATRONS, desc = "山海伏兽-获取驻守在兽蛋的门客")
public class CrossSonHaiGetInEggPatronsIdCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        SonHaiProto.SonHaiGetInEggPatronsReqMsg reqMsg = SonHaiProto.SonHaiGetInEggPatronsReqMsg.parseFrom(packet.getBytes());
        SonHaiProto.SonHaiGetInEggPatronsRespMsg.Builder respMsg = SonHaiProto.SonHaiGetInEggPatronsRespMsg.newBuilder();
        CrossSonHaiActivity activity = CrossSonHaiActivityMgr.getActivity(reqMsg.getActivityId(), groupId);
        if (activity == null) {
            respMsg.setRet(GameErrorCode.E_SON_HAI_ACTIVITY_NOT_FOUND);
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_SON_HAI_GET_IN_EGG_PATRONS, respMsg));
            return;
        }
        //获取驻守在兽蛋的门客
        try {
            //获取驻守在兽蛋的门客
            Map<Integer, SonHaiPatronsEgg> map = activity.getInEggPatronsMap(packet.getPlayerId());
            //构造PB
            respMsg.setRet(0);
            for (SonHaiPatronsEgg patronsEgg : map.values()) {
                SonHaiProto.SonHaiPatronsEggData.Builder builder = SonHaiProto.SonHaiPatronsEggData.newBuilder();
                builder.setPatronsId(patronsEgg.getPatronsId());
                builder.setEggConfigId(patronsEgg.getEggData().getEggConfigId());
                builder.setEggName(ServerLanguageMgr.getContent(patronsEgg.getEggData().getEggName(), reqMsg.getLanguage()));
                respMsg.addPatronsEgg(builder);
            }
        } catch (BusinessException e) {
            respMsg.setRet(e.getCode());
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_SON_HAI_GET_IN_EGG_PATRONS, respMsg));
    }

    @Override
    public void sendData() {

    }
}
